package com.dongbing.demo.modules.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dongbing.demo.modules.system.enity.User;
import com.dongbing.demo.modules.system.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author  MrDong
 * @create  2021/6/18 17:02
 * @desc    mybatis-plus分页
 **/
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/page")
    public void userPage(){

        LambdaQueryWrapper<User> userLambdaQueryWrapper = Wrappers.lambdaQuery();
        userLambdaQueryWrapper.like(User::getStuName , "王");


        Page<User> userPage = new Page<>(3, 3);
        IPage<User> userIPage = userMapper.selectPage(userPage , userLambdaQueryWrapper);
        System.out.println("总页数： "+userIPage.getPages());
        System.out.println("总记录数： "+userIPage.getTotal());
        userIPage.getRecords().forEach(System.out::println);
    }

    @PostMapping("/test")
    public String test(){

        List<User> users = userMapper.selectList(null);
        User user = userMapper.selectById(2);
        //user.getStuName(System.out::println);
        users.forEach(System.out::println);
        return "SUCCESS ~";
    }

    @RequestMapping("/list")
    public Object testTwo(){
        return userMapper.selectList(null);
    }
}
